#include <bits/stdc++.h>

using namespace std;
const int MAX=100010,MOD=1000000007;

int main_1093()
{
    char str[MAX]={0};
    int leftNumP[MAX]={0};
    scanf("%s",str);
    int len=strlen(str),ans=0,rightNumT=0;
    if (str[0]=='P')
    {
        leftNumP[0]=1;
    }
    for (int i=1;i<len ;++i )
    {
        if (str[i]=='P')
        {
            leftNumP[i]=leftNumP[i-1]+1;
        }
        else
        {
            leftNumP[i]=leftNumP[i-1];
        }
    }
    for (int j=len-1; j>=0;--j )
    {
        if (str[j]=='T')
        {
            ++rightNumT;
        }else if(str[j]=='A')
        {
            ans=(ans+leftNumP[j]*rightNumT)%MOD;
        }
    }
    printf("%d\n",ans);
	return 0;
}
